﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nage.Algorithms.Population;
using Nage.Algorithms.RandomGenerators;
using Nage.Algorithms.Evolution;
using Nage.Examples.Rastrigin.Solution;

namespace Nage.Examples.Rastrigin.Evolution
{
    public class CoordinatesMutation : ISolutionMutation<Coordinates>
    {
        public Double MutationRate { get; private set; }
        public Double Delta { get; private set; }

        public CoordinatesMutation(double mutationRate, double delta)
        {
            MutationRate = mutationRate;
            Delta = delta;
        }

        public Coordinates Mutate(Coordinates solution)
        {
            Coordinates mutSolution = new Coordinates(solution.Vector.ToArray());
            for (int i = 0; i < solution.Vector.Length; i++)
            {
                if (Rng.GetInstance().Draw(MutationRate))
                {
                    solution.Vector[i] = solution.Vector[i] + Rng.GetInstance().GetDouble(-Delta, Delta);
                }
            }
            return mutSolution;
        }

    }
}
